package com.ccr.roeun.moneymanager.app;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ccr.roeun.moneymanager.core.UnitOfMeasure;

import java.util.List;

public class UnitOfMeasureAdapter extends BaseAdapter {

    Context context;
    List<UnitOfMeasure> unitofMeasures;

    public UnitOfMeasureAdapter(Context context,List<UnitOfMeasure> unitofMeasures ) {
        this.context = context;
        this.unitofMeasures = unitofMeasures;
    }

    @Override
    public int getCount() {
        return unitofMeasures.size();
    }

    @Override
    public Object getItem(int position) {
        return unitofMeasures.get(position);
    }

    @Override
    public long getItemId(int position) {
        return unitofMeasures.indexOf(getItem(position));
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            LayoutInflater mLayoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = mLayoutInflater.inflate(R.layout.list_item_unit_of_measure, null);
        }
        ImageView imageView =(ImageView) convertView.findViewById(R.id.icon);
        TextView textView = (TextView) convertView.findViewById(R.id.firstLine);
        UnitOfMeasure unitOfMeasure = unitofMeasures.get(position);
        textView.setText(unitOfMeasure.getName());
        return convertView;
    }
}
